package="${HOME}/temp"
while getopts ":p:j:" opt
do
    case $opt in
        p)
        package=$OPTARG
        echo "您输入的解压路径:$package"
        ;;
        j)
        jar=$OPTARG
        echo "您输入的解压路径:$OPTARG"
        ;;
        ?)
        echo "未知参数,你可以这样使用 : sh exeupdate.sh -p /var "
        exit 1;;
    esac
done
if [[ ! -d ${package} ]]
then
  mkdir -p "${package}"
  if [[ $? -eq 1 ]]
  then
    sudo mkdir -p "${package}"
  fi
fi
sudo cp -rvf "${jar}" "${package}/"
cd "${package}" || exit
jar -xf "${package}/${jar##*/}" BOOT-INF/classes/sql/update
cd - || exit

sqls=$(ls -1 "${package}/BOOT-INF/classes/sql/update" | awk -F '[-.]+' '{print $0" "$1}' | sort -nk2 | awk '{print $1}')
for sql in "${sqls[@]}"
do
  mysql -hlocalhost -uyapai -pypkj@1234 -D "${sql%%_*}" -f < "${package}/BOOT-INF/classes/sql/update/${sql}"
done

